package org.example.chat.controller;

import org.example.chat.api.CommonResult;
import org.example.chat.entity.RegionInfo;
import org.example.chat.service.IRegionInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/region")
public class RegionInfoController {

    @Autowired
    private IRegionInfoService regionInfoService;


    @GetMapping("/getBySuperiorCode")
    public CommonResult<List<RegionInfo>> getRegionInfosBySuperiorCode(@RequestParam(required = true) String code) {
        List<RegionInfo> regionInfos = regionInfoService.getRegionInfoBySuperiorCode(code);
        return CommonResult.success(regionInfos);
    }

    @GetMapping("/getSubByParName")
    public CommonResult<List<RegionInfo>> getSubRegionInfosByParentName(String name) {
        List<RegionInfo> regionInfos = regionInfoService.queryRegionInfoByName(name);
        return CommonResult.success(regionInfos);
    }
}
